package application.gui.workerWindow;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import application.LoginAndAdministrationModule.PersonData;
import application.gui.clientWindow.ClientHomePage;
import application.gui.main.startWindow.Homepage;

public class WorkerHomePage extends ClientHomePage{

	public WorkerHomePage(PersonData loggedUser, Homepage f) {
		super(loggedUser, f);
		createMenuPanel();
		setStatusPanel(new ChangeParcelStatusPanel(this, getDb()));
		add(getStatusPanel());
		getStatusPanel().setBounds(200, 120, 600, 480);
		statusPanel.setVisible(false);
		setClientPanel(new ClientTablePanel(this, getDb(), loggedUser));
		add(getClientPanel());
		clientPanel.setVisible(false);
		getClientPanel().setBounds(200, 120, 600, 480);
		setListeners();
		// TODO Auto-generated constructor stub
	}
	
	private void createMenuPanel(){
		changeParcelStatus = new JButton("Zmień status przesyłki");
		this.getMenuPanel().add(changeParcelStatus);
		changeParcelStatus.setBounds(0, 250, 200, 30);
		clientList = new JButton("Lista klientów");
		this.getMenuPanel().add(clientList);
		clientList.setBounds(0, 280, 200, 30);
	}
	
	private void setListeners(){
		changeParcelStatus.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				WorkerHomePage.this.getMainPanel().setVisible(false);
				WorkerHomePage.this.getNewParcelPanel().setVisible(false);
				WorkerHomePage.this.getShowParcelPanel().setVisible(false);
				WorkerHomePage.this.getDataPanel().setVisible(false);
				WorkerHomePage.this.getDeliveryPanel().setVisible(false);
				getClientPanel().setVisible(false);
				getStatusPanel().setVisible(true);
			}
		});
		clientList.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				WorkerHomePage.this.getMainPanel().setVisible(false);
				WorkerHomePage.this.getNewParcelPanel().setVisible(false);
				WorkerHomePage.this.getShowParcelPanel().setVisible(false);
				WorkerHomePage.this.getDataPanel().setVisible(false);
				WorkerHomePage.this.getDeliveryPanel().setVisible(false);
				getStatusPanel().setVisible(false);
				getClientPanel().setVisible(true);
			}
		});
		getAddParcel().addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				hidePanels();
			}
		});

		getShowMyParcel().addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				hidePanels();
			}
		});

		getParcelHistory().addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				hidePanels();
			}
		});

		getCheckDeliveryStatusButton().addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				hidePanels();
			}
		});
		
		getChangeData().addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				hidePanels();
			}
		});
		
	}
	private void hidePanels(){
		clientPanel.setVisible(false);
		statusPanel.setVisible(false);
	}
	
	public ChangeParcelStatusPanel getStatusPanel() {
		return statusPanel;
	}

	public void setStatusPanel(ChangeParcelStatusPanel statusPanel) {
		this.statusPanel = statusPanel;
	}

	public ClientTablePanel getClientPanel() {
		return clientPanel;
	}

	public void setClientPanel(ClientTablePanel clientPanel) {
		this.clientPanel = clientPanel;
	}

	private ChangeParcelStatusPanel statusPanel;
	private ClientTablePanel clientPanel;
	private JButton changeParcelStatus;
	private JButton clientList;
	public JButton getChangeParcelStatus() {
		return changeParcelStatus;
	}

	public JButton getClientList() {
		return clientList;
	}

}
